//
//  UpdateGroupVC.swift
//  YueChat
//
//  Created by 1 on 2024/10/29.
//

import UIKit

class UpdateGroupVC: BaseVC {

    @IBOutlet weak var textField: UITextField!
    var group = DMCCGroup()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = kGrayBG
        
        
        
    }
    
   
    
    init(group: DMCCGroup = DMCCGroup()) {
        super.init(nibName: nil, bundle: nil)
        self.group = group
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    @IBAction func onBack(_ sender: Any) {
        self.dismiss(animated: true)
    }
    
    @IBAction func done(_ sender: Any) {
        if textField.text!.count > 0 {
            
            SVProgressHUD.show()
            Task{
                let (_,error) = await ghttpService.requestUploadGroupMember(textField.text!, group.groupId)
                    await MainActor.run {
                        SVProgressHUD.dismiss()
                        if error == nil{
                            
                            MHAlert.showMessage("已激活")
                            Task {
                                 _ = await gosnGroup.fetchGroupInfo(group.groupId)
                                
                                DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: DispatchWorkItem(block: {
                                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: kGroupUpdateChanged), object: nil, userInfo: nil)
                                    self.dismiss()
                                }))
                            }
                        }else{
                            
                            MHAlert.showMessage(error!.description)
                        }
                    }
                }
        }
    }
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
